package main

import (
	"fmt"
)

type ListNode struct {
	Val  int
	Next *ListNode
}

/**
 *
 * @param pHead ListNode类
 * @return ListNode类
 */
func ReverseList(pHead *ListNode) *ListNode {
	var newHead *ListNode
	var node *ListNode
	for pHead != nil {
		node = pHead
		pHead = pHead.Next

		node.Next = newHead
		newHead = node
	}
	return newHead
}

func main() {
	list1 := ListNode{1, nil}
	list2 := ListNode{2, &list1}
	list3 := ListNode{3, &list2}
	newList := ReverseList(&list3)
	fmt.Println(newList.Val, newList.Next.Val, newList.Next.Next.Val)
}
